home *** CD-ROM | disk | FTP | other *** search
- #include "OHScrollableView.h"
- #include "kSanAGWindow.h"
- #include "kSanSimAtomtypes.h"
- void swapColours( AGWindow *ag) ;
- void stashColours( AGWindow *ag, RGBColor *rgbs) ;
- void unstashColours( AGWindow *ag, RGBColor *rgbs) ;
- void findLinePoints( AGWindow *ag, cubeFrameData *thisFrame, kSanMatrix * trix, Point offset);
- void setLineOrder(short * lineValPtr, short * lineOrderPtr); // sort by zval
- void checkLineOrder(short index, short * myPtr,short * lineValPtr);
- void drawLines(cubeFrameData *thisFrame, short begin, short end) ;
- void findParticles( AGWindow *ag, particle *basePart, Point offset); //findParticles should not be in header
- void findBonds( AGWindow *ag, particle *basePart, Point offset); //findBonds should not be in header
- void drawContents( AGWindow *ag);
- void sortParticles( AGWindow *ag) ;
-
- void drawHackLines(RGBColor *rgb, cubeFrameData *thisFrame, short begin, short end) ;
- void drawHackContents(RGBColor *rgb, AGWindow *ag);
- short AGWindowDrawHacked(KozoDispatchStack *ds, viewDrawArgs *args);
- short AGWindowDrawRegular(KozoDispatchStack *ds, viewDrawArgs *args);
-
- short agCheckOrderList(AGWindow *ag)
- {
- if (ag->orderListDirty)
- {
- AGWindowInitializeWindowOrderList(ag);
- }
- return(noErr);
- }
- short agCheckPartList(AGWindow *ag)
- {
- if (ag->partListDirty)
- {
- //AGWindowReinitializePartList(ag);
- BitListToOHList( &ag->partBits, &ag->particleList) ;
- ag->partListDirty = false;
- }
- return(noErr);
- }
- short agCheckGrafDataList(AGWindow *ag)
- {
- if (ag->grafDataDirty)
- {
- AGWindowReinitializeGrafDataList(ag);
- }
- return(noErr);
- }
-
- short AGWindowDraw(KozoDispatchStack *ds, viewDrawArgs *args)
- {
- AGWindow *ag;
- ag = KDSGetPrivateData(ds, ClassAGWindow );
- if (ag->nowBeingHacked)
- {
- AGWindowDrawHacked(ds,args);
- }
- else
- {
- AGWindowDrawRegular(ds,args);
- }
- return (noErr);
- }
- CopyGWorldToGWorld (GWorldPtr gwa, GWorldPtr gwb);
- CopyGWorldToGWorld (GWorldPtr gwa, GWorldPtr gwb)
- { // must lock pixels outside this routine
- short err = noErr;
-
- PixMapHandle PixMapA;
- PixMapHandle PixMapB;
- GWorldFlags AFlags;
- GWorldFlags BFlags;
-
- PixMapA = GetGWorldPixMap(gwa);
- PixMapB = GetGWorldPixMap(gwb);
- AFlags = GetPixelsState(PixMapA);
- BFlags = GetPixelsState(PixMapB);
- LockPixels (PixMapA);
- LockPixels (PixMapB);
-
- CopyBits((BitMapPtr)(*PixMapA), // from here
- (BitMapPtr)(*PixMapB), &gwb->portRect,&gwb->portRect, adMin , nilPointer);
-
- SetPixelsState(PixMapA, AFlags);
- SetPixelsState(PixMapB, BFlags);
- // if (err != 0) doAlert("\pQD Error");
- return (noErr);
- }
-
-
- short doAGHackDrawing(AGWindow *ag, particle * basePart, viewDrawArgs *args, RGBColor *rgb);
- short doAGHackDrawing(AGWindow *ag, particle * basePart, viewDrawArgs *args, RGBColor *rgb)
- {
-
- cubeFrameData aCubeFrame;
- kSanMatrix trix;
-
- getPrimitiveVectors( ag->sim, &trix);
- findLinePoints( ag, &aCubeFrame, &trix, args->offset);
- setLineOrder(&(aCubeFrame.edgeValues[0]), &(aCubeFrame.edgeOrder[0]));
- ag->windowView.lastOffsetUsed = args->offset;
-
-
- drawHackLines(rgb, &aCubeFrame, 0 , 7); // firstEightLines
- PenPat (&qd.black);
-
- findParticles( ag, basePart, args->offset);
- sortParticles ( ag );
-
- // if (ag->windowView.showBonds == true)
- // {
- // findBonds( ag, basePart, args->offset);
- // }
- drawHackContents(rgb, ag);
-
-
- // drawColourBar(theWindow); taken out for first compile
-
- drawHackLines(rgb, &aCubeFrame, 8 , 11); // lastFourLines
- return (noErr);
- }
-
- short AGWindowDrawHacked(KozoDispatchStack *ds, viewDrawArgs *args)
- {
- grafData *theGrafPtr;
- particle * basePart;
- kozoObject *agObj = ds->obj;
- AGWindow *ag;
- OHBufferedView *bv = bvData(ds->obj);
- kSanMatrix oldTrix;
- RGBColor aColor;
-
- GDHandle oldGD;
- GWorldPtr oldGW;
-
-
- ag = KDSGetPrivateData(ds, ClassAGWindow );
-
- theGrafPtr = AGWindowLockGrafData( ag);
- basePart = simLockParts( ag->sim);
- ag->atArray = simLockAtomTypes( ag->sim);
- setRGB (&aColor,65535,30000,30000);
- oldTrix = ag->windowView.viewMatrix;
-
- PenMode (patCopy);
- PenPat (&qd.black);
-
- Spin3dMatrixInDegreesD(&ag->windowView.viewMatrix, 3, 0, 0);
-
-
-
-
- GetGWorld( &oldGW, &oldGD);
- SetGWorld( ag->redChannel, nilPointer);
-
-
- EraseRect(&ag->redChannel->portRect);
- doAGHackDrawing(ag, basePart, args, &aColor);
- Spin3dMatrixInDegreesD(&ag->windowView.viewMatrix, -6, 0, 0);
- SetGWorld( ag->blueChannel, nilPointer);
-
-
- EraseRect(&ag->blueChannel->portRect);
- setRGB (&aColor,30000,65535,65535);
- doAGHackDrawing(ag, basePart, args, &aColor);
-
-
- SetGWorld(oldGW,oldGD);
-
- // now copy into the real bv
- CopyGWorldToGWorld (ag->redChannel, bv->world);
- CopyGWorldToGWorld (ag->blueChannel, bv->world);
- ag->windowView.viewMatrix = oldTrix;
-
- PenPat (&qd.black);
-
- AGWindowReleaseGrafData( ag);
- simReleaseParts( ag->sim);
- simReleaseAtomTypes( ag->sim);
- KDSReturnContinue(ds);
- }
- short AGWindowDrawRegular(KozoDispatchStack *ds, viewDrawArgs *args)
- {
- grafData *theGrafPtr;
- particle * basePart;
- kozoObject *agObj = ds->obj;
- AGWindow *ag;
- kSanMatrix trix;
- cubeFrameData aCubeFrame;
-
- ag = KDSGetPrivateData(ds, ClassAGWindow );
-
- theGrafPtr = AGWindowLockGrafData( ag);
- basePart = simLockParts( ag->sim);
- ag->atArray = simLockAtomTypes( ag->sim);
-
-
- PenMode (patCopy);
- PenPat (&qd.black);
- getPrimitiveVectors( ag->sim, &trix);
- findLinePoints( ag, &aCubeFrame, &trix, args->offset);
- setLineOrder(&(aCubeFrame.edgeValues[0]), &(aCubeFrame.edgeOrder[0]));
- ag->windowView.lastOffsetUsed = args->offset;
-
-
- #ifndef __2DVectors__
- drawLines(&aCubeFrame, 0 , 7); // firstEightLines
- #else
- drawLines(&aCubeFrame, 0 , 3); // all four Lines
- #endif
- PenPat (&qd.black);
-
-
- if (ag->doColourCalc)
- {
- findParticles( ag, basePart, args->offset);
-
- #ifndef __2DVectors__
- sortParticles( ag);
- #endif
-
- if (ag->cpi) ag->cpi->colourParticleList ( ag->cpi, ag->sim, theGrafPtr, AGWindowNumParts(ag));
- }
- else
- {
- RGBColor *tempRGB = nilPointer;
- long count = AGWindowNumParts(ag);
- tempRGB = (RGBColor *) NewPtr (sizeof(RGBColor) * count);
- if (tempRGB != nilPointer) stashColours( ag, tempRGB);
- findParticles( ag, basePart, args->offset);
- if (tempRGB != nilPointer) unstashColours( ag, tempRGB);
- #ifndef __2DVectors__
- sortParticles ( ag );
- #endif
- if (tempRGB != nilPointer) DisposePtr ((Ptr)tempRGB);
- }
-
-
- if (ag->windowView.showBonds == true)
- {
- findBonds( ag, basePart, args->offset);
- }
- drawContents( ag);
-
-
- // drawColourBar(theWindow); taken out for first compile
-
-
-
- #ifndef __2DVectors__
- drawLines(&aCubeFrame, 8 , 11); // lastFourLines
- #endif
-
- PenPat (&qd.black);
-
- AGWindowReleaseGrafData( ag);
- simReleaseParts( ag->sim);
- simReleaseAtomTypes( ag->sim);
-
- KDSReturnContinue(ds);
- }
-
-
- void stashColours(AGWindow *ag, RGBColor *rgbs)
- {
- long count;
- long i;
- // long *orderListPtr;
- grafData * theGrafPtr;
-
- agCheckOrderList(ag);
- theGrafPtr = AGWindowLockGrafDataC( ag, &count);
- // orderListPtr = lockList( &ag->orderList);
- for (i = 0; i< count; ++i)
- {
- rgbs[i] = theGrafPtr[i].colour;
- }
- AGWindowReleaseGrafData( ag);
- // releaseList( &ag->orderList);
-
- }
-
- void unstashColours(AGWindow *ag, RGBColor *rgbs)
- {
- long count;
- long i;
- long *orderListPtr;
- grafData * theGrafPtr;
- count = AGWindowNumParts(ag);
-
-
- agCheckOrderList(ag);
- theGrafPtr = AGWindowLockGrafData( ag);
- orderListPtr = lockList( &ag->orderList);
- for (i = 0; i< count; ++i)
- {
- theGrafPtr[i].colour = rgbs[orderListPtr[i]];
- }
- AGWindowReleaseGrafData( ag);
- releaseList( &ag->orderList);
-
- }
-
- #ifndef __2DVectors__
- double agParticleGetSortingValue(anyList *list, long index, void *param) ;
- double agParticleGetSortingValue(anyList *list, long index, void *param)
- {
- grafData *theGrafPtr = (grafData *) param;
- long theListValue = ((long *)(*list->listData))[index];
- return(theGrafPtr[theListValue].graphc );
- }
-
- void sortParticles(AGWindow *ag)
- {
- grafData *theGrafPtr;
-
- agCheckOrderList(ag);
- theGrafPtr = AGWindowLockGrafData( ag );
- if (theGrafPtr) anylistValueSort((anyList *)&ag->orderList, agParticleGetSortingValue, (short (*) (anyList *, long, long)) OHListSwapItemsFunc, theGrafPtr);
- AGWindowReleaseGrafData( ag );
- }
- #endif
-
- /*
- void sortParticles(AGWindow *ag)
- {
- long * orderList;
- lksPtr firstlink;
- lksPtr thislink;
- lksPtr somelink;
- lksPtr nextlink;
- lksPtr myPtr;
- long i = 0;
- long j = 0;
- long count;
-
- count = OHListCount(&ag->partList);
- if (count > 0)
- {
- myPtr = simLockLinkArray( ag->sim);
- orderList = lockList( &ag->orderList);
- firstlink = &(myPtr[0]);
- firstlink->label = 0;
- firstlink->value = theGrafPtr[i].graphc;
- firstlink->next = nilPointer;
-
- for (i=1 ; i < count ; ++i)
- {
- thislink = &(myPtr[i]);
- thislink->label = i;
- thislink->value = theGrafPtr[i].graphc;
- if (thislink->value >= firstlink->value) // firstlink has highest value of stack
- {
- thislink->next = firstlink; // make thislink the top of stack
- firstlink = thislink;
- }
- else
- {
- somelink = firstlink; // find place in stack
- nextlink = somelink->next;
- while ((nextlink != nilPointer) && (thislink->value < nextlink->value) )
-
- {
- somelink = nextlink;
- nextlink = somelink->next;
- }
-
- // we drop through this while statement when we are at the end of the list or when
- // the value of thislink is in between somelink and nextlink
-
- thislink->next = nextlink;
- somelink->next = thislink;
- }
- }
- somelink = firstlink;
- for(i= (OHListCount(&ag->partList)) -1 ; i>=0 ; i = i-1)
- {
- orderList[i] = somelink->label;
- somelink = somelink->next;
- }
- AGWindowReleaseGrafData( ag );
- simReleaseLinkArray( ag->sim);
- releaseList( &ag->orderList );
- ag->orderListDirty = false;
- }
- }
- */
- void findLinePoints(AGWindow *ag, cubeFrameData *thisFrame, kSanMatrix * trix, Point offset)
- {
-
- short j,k;
- kSanVector lineBeginning;
- kSanVector lineEnd;
- kSanVector linePointOne;
- kSanVector linePointTwo;
- // depthFactor, viewLen;
- //float mag;
- viewInfo *vInfo;
- OHView *view = viewData (ag->win->obj);
-
- kSanMatrix cMat;
- kSanMatrix * theMatPtr;
- vInfo = &ag->windowView;
- theMatPtr = &(vInfo->viewMatrix);
-
- //mag = vInfo->magnification;
-
- getCramerskSanOperatorsD(theMatPtr, &cMat);
- multkSanMatrixD( &cMat , vInfo->magnification, &cMat);
-
- for (j= 0; j< NUMCUBEEDGES ;++j)
- {
- kSanVector startCorner;
- kSanVector endCorner;
-
-
- thisFrame->edgeValues[j] = 0;
- startCorner = gCubeVerticies[gCubeEdges[j].start];
- endCorner = gCubeVerticies[gCubeEdges[j].end];
-
- vecDotkSanMatrixD( &startCorner, trix, &lineBeginning);
- vecDotkSanMatrixD( &endCorner, trix, &lineEnd);
-
- for (k= 0; k<=5 ;++k)
- {
- float multFactorOne = ((float)k) / 5.0 ;
- float multFactorTwo = ((float)(5 - k)) / 5.0 ;
- kSanVector vecSum;
- kSanVector graphicsCoords;
- multkSanVectorD(&lineBeginning, multFactorOne, &linePointOne);
- multkSanVectorD(&lineEnd, multFactorTwo, &linePointTwo);
- addkSanVectorsD (&linePointOne , &linePointTwo, &vecSum);
-
- cramersCoordsOfkSanPoint ( &cMat, &vecSum, &graphicsCoords);
-
-
- #ifndef __2DVectors__
- thisFrame->edgeValues[j] += graphicsCoords.c;
- #endif
- // if (graphC < viewLen) // floatToShort handles nans
- {
- float aFloat, bFloat;
- bFloat = (- graphicsCoords.b) + offset.v;
- aFloat = ( graphicsCoords.a) + offset.h;
- thisFrame->edge[j].edgePoints[k].v = floatToShort (bFloat);
- thisFrame->edge[j].edgePoints[k].h = floatToShort (aFloat);
- }
- }
- }
- }
-
- void setLineOrder(short * lineValPtr, short * lineOrderPtr) // sort by zval
- {
- short i;
- for (i = 0;i<NUMCUBEEDGES;++i)
- {
- lineOrderPtr[i] = i;
- #ifndef __2DVectors__
- checkLineOrder(i, lineOrderPtr, lineValPtr);
- #endif
- }
- }
- void checkLineOrder(short index, short * myPtr,short * lineValPtr)
- {
- short temp;
- if (index > 0)
- {
- if (lineValPtr[myPtr[index]] < lineValPtr[myPtr[index-1]])
- {
- temp = myPtr[index];
- myPtr[index] = myPtr[index-1];
- myPtr[index-1] = temp;
- checkLineOrder((index-1), myPtr, lineValPtr);
- }
- }
- }
- void drawLines(cubeFrameData *thisFrame, short begin, short end)
- {
- int i, j;
- short whichEdge;
- LinePair *myPair;
- RGBColor lpColours[4] = {{0,0,0}, {0xFFFF, 0x3FFF, 0x3FFF}, {0x3FFF, 0xFFFF, 0x3FFF}, {0x3FFF, 0x3FFF, 0xFFFF}};
- Point *myPoint;
- PenSize(2,2);
- PenPat(&(qd.dkGray));
- for (i = begin; i<=end; ++i)
- {
- whichEdge = thisFrame->edgeOrder[i];
- myPair = &(gCubeEdges[whichEdge]); // retrieve the pair from the global list
- RGBForeColor(&lpColours[myPair->colour]);
- myPoint = &(thisFrame->edge[whichEdge].edgePoints[0]);
- MoveTo(myPoint->h, myPoint->v);
- for (j = 1; j <= 5 ; ++j)
- {
- myPoint = &(thisFrame->edge[whichEdge].edgePoints[j]);
- LineTo(myPoint->h, myPoint->v);
- }
- }
- PenSize(1,1);
- }
- void drawHackLines(RGBColor *rgb, cubeFrameData *thisFrame, short begin, short end)
- {
- int i, j;
- short whichEdge;
- LinePair *myPair;
- Point *myPoint;
- PenSize(2,2);
- PenPat(&(qd.dkGray));
- RGBForeColor(rgb);
- for (i = begin; i<=end; ++i)
- {
- whichEdge = thisFrame->edgeOrder[i];
- myPair = &(gCubeEdges[whichEdge]); // retrieve the pair from the global list
- myPoint = &(thisFrame->edge[whichEdge].edgePoints[0]);
- MoveTo(myPoint->h, myPoint->v);
- for (j = 1; j <= 5 ; ++j)
- {
- myPoint = &(thisFrame->edge[whichEdge].edgePoints[j]);
- LineTo(myPoint->h, myPoint->v);
- }
- }
- PenSize(1,1);
- }
- void setForeColourNoShade(AGWindow *ag, grafData *thisPart)
- {
- #pragma unused(ag)
- RGBForeColor (&(thisPart->colour));
- }
-
- #ifndef __2DVectors__
- void setForeColourWithShade(AGWindow *ag, grafData *thisGrafPtr)
- {
- RGBColor shadedColour;
- float range;
- float neutralDepth;
- float disp;
- float factor;
-
- neutralDepth = ag->windowView.neutralShadeDepth * ag->windowView.magnification;
- range = ag->windowView.shadeRange * ag->windowView.magnification;
- disp = thisGrafPtr->graphc - neutralDepth;
- shadedColour = thisGrafPtr->colour;
- if (disp > 0)
- {
- factor = erf(disp/range);
- shadedColour.red += (0xFFFF - thisGrafPtr->colour.red) * factor;
- shadedColour.blue +=(0xFFFF - thisGrafPtr->colour.blue) * factor;
- shadedColour.green +=(0xFFFF - thisGrafPtr->colour.green) * factor;
- }
- else if (disp < 0)
- {
- factor = erf(-disp/range);
- shadedColour.red -= (0xFFFF - thisGrafPtr->colour.red) * factor;
- shadedColour.blue -=(0xFFFF - thisGrafPtr->colour.blue) * factor;
- shadedColour.green -=(0xFFFF - thisGrafPtr->colour.green) * factor;
- }
- RGBForeColor (&shadedColour);
- }
- #endif
-
- void drawContents(AGWindow *ag)
- {
- long i;
- long count;
- long * listPtr;
- grafData *thisPart;
- grafData *thisGrafPtr;
- RGBColor blackRGB;
-
- agCheckOrderList(ag);
- thisGrafPtr =AGWindowLockGrafData( ag);
- listPtr = lockList( &ag->orderList);
-
- // if (ag->transparentAtoms) PenMode (addOver);
- // else
- PenMode (srcCopy);
- PenSize (1,1);
- blackRGB = getColour(myBlackColour);
- count = AGWindowNumParts(ag);
- if (ag->windowView.showBonds)
- {
- RGBForeColor (&blackRGB);
- PenPat(&qd.black);
- for (i= 0; i<count ; ++i)
- {
- thisPart = &(thisGrafPtr[listPtr[i]]);
- if (thisPart->inWindow)
- {
- /*
- for (k = 0; k< thisPart->howManyBackbonds;++k)
- {
- MoveTo(thisPart->backbondStart[k].h,thisPart->backbondStart[k].v);
- LineTo(thisPart->backbondEnd[k].h,thisPart->backbondEnd[k].v);
- }
- */
- ag->setForeColour ( ag, thisPart);
-
-
- if (!thisPart->selected)
- {
- PaintOval(&(thisPart->circle));
- RGBForeColor (&blackRGB);
- FrameOval(&(thisPart->circle));
- }
- else
- {
- PenPat(&qd.gray);
- PaintOval(&(thisPart->circle));
- PenPat(&qd.black);
- PenSize (2,2);
- RGBForeColor (&blackRGB);
- FrameOval(&(thisPart->circle));
- PenSize (1,1);
- }
- /*
- for (k = 0; k< thisPart->howManyForebonds;++k)
- {
- MoveTo(thisPart->forebondStart[k].h,thisPart->forebondStart[k].v);
- LineTo(thisPart->forebondEnd[k].h,thisPart->forebondEnd[k].v);
- }
- */
- }
- else
- {
- }
- }
- }
- else // don't show bonds
- {
- PenPat(&qd.black);
- for (i= 0; i<count ; ++i)
- {
- thisPart = &(thisGrafPtr[listPtr[i]]);
- if (thisPart->inWindow)
- {
- ag->setForeColour ( ag, thisPart);
- if (!thisPart->selected)
- {
-
- PaintOval(&(thisPart->circle));
- RGBForeColor (&blackRGB);
- FrameOval(&(thisPart->circle));
- }
- else
- {
- PenPat(&qd.gray);
- PaintOval(&(thisPart->circle));
- PenPat(&qd.black);
- PenSize (2,2);
- RGBForeColor (&blackRGB);
- FrameOval(&(thisPart->circle));
- PenSize (1,1);
- }
- }
- }
- }
- AGWindowReleaseGrafData( ag);
- releaseList( &ag->orderList);
- }
- void drawHackContents(RGBColor *rgb, AGWindow *ag)
- {
- long i;
- long count;
- long * listPtr;
- grafData *thisPart;
- grafData *thisGrafPtr;
-
- agCheckOrderList(ag);
- thisGrafPtr =AGWindowLockGrafData( ag);
- listPtr = lockList( &ag->orderList);
-
- PenMode (srcCopy);
- PenSize (1,1);
- count = AGWindowNumParts(ag);
- if (ag->windowView.showBonds)
- {
- RGBForeColor (rgb);
- PenPat(&qd.black);
- for (i= 0; i<count ; ++i)
- {
- thisPart = &(thisGrafPtr[listPtr[i]]);
- if (thisPart->inWindow)
- {
- /*
- for (k = 0; k< thisPart->howManyBackbonds;++k)
- {
- MoveTo(thisPart->backbondStart[k].h,thisPart->backbondStart[k].v);
- LineTo(thisPart->backbondEnd[k].h,thisPart->backbondEnd[k].v);
- }
- */
- ag->setForeColour ( ag, thisPart);
-
-
- if (!thisPart->selected)
- {
- PaintOval(&(thisPart->circle));
- RGBForeColor (rgb);
- FrameOval(&(thisPart->circle));
- }
- else
- {
- PenPat(&qd.gray);
- PaintOval(&(thisPart->circle));
- PenPat(&qd.black);
- PenSize (2,2);
- RGBForeColor (rgb);
- FrameOval(&(thisPart->circle));
- PenSize (1,1);
- }
- /*
- for (k = 0; k< thisPart->howManyForebonds;++k)
- {
- MoveTo(thisPart->forebondStart[k].h,thisPart->forebondStart[k].v);
- LineTo(thisPart->forebondEnd[k].h,thisPart->forebondEnd[k].v);
- }
- */
- }
- else
- {
- }
- }
- }
- else // don't show bonds
- {
- RGBColor drawThisColor = *rgb;
- drawThisColor.red = (65535 + rgb->red) / 2;
- drawThisColor.green = (65535 + rgb->green) / 2;
- drawThisColor.blue = (65535 + rgb->blue) / 2;
- PenPat(&qd.black);
- for (i= 0; i<count ; ++i)
- {
- thisPart = &(thisGrafPtr[listPtr[i]]);
- if (thisPart->inWindow)
- {
- if (!thisPart->selected)
- {
- RGBForeColor (&drawThisColor);
- PaintOval(&thisPart->circle);
- RGBForeColor (rgb);
- FrameOval(&(thisPart->circle));
- }
- }
- }
- }
- AGWindowReleaseGrafData( ag);
- releaseList( &ag->orderList);
- }
-
- void findParticles(AGWindow *ag, particle *basePart, Point offset)
- { // you must set up the ag->atArray list before calling!
- short err = noErr;
- short j, realSize, halfSize;
- long howManyParts;
- long *orderListPtr;
- long * partListPtr;
- grafData * theGrafPtr;
- grafData *thisGrafPtr;
- viewInfo *theView;
- kSanVector graphicsCoords; // was graphA, graphB
- // kSanVector calcCoords;// was calcX, calcY
- // float depthFactor;
- // float sizeFactor; // cellVec, halfCellVec;
- kSanMatrix cMat;
- // partSize;
- OHScrollableView *sv = svData (ag->win->obj);
- Rect visibleRect;
-
- visibleRect = sv->viewableBounds;
-
- agCheckPartList(ag);
- agCheckOrderList(ag);
- theGrafPtr = AGWindowLockGrafData(ag);
- orderListPtr = lockList( &ag->orderList);
- partListPtr = lockList( &ag->particleList);
- howManyParts = AGWindowNumParts(ag) ;
-
- theView = &(ag->windowView);
-
- getCramerskSanOperatorsD(&(theView->viewMatrix), &cMat);
- multkSanMatrixD(&cMat, theView->magnification, &cMat);
-
- for (j= 0; j<howManyParts ;++j)
- {
- // copy the order of the particles in the grafData structure to the partList
- partListPtr[j] = theGrafPtr[orderListPtr[j]].index ;
- }
- for (j= 0; j<howManyParts ;++j)
- {
- Rect *thisCircle;
- long partArrIndex;
- partArrIndex = partListPtr[j];
-
- /* calcX = basePart->basePosition[partArrIndex].a;
- calcY = basePart->basePosition[partArrIndex].b;
- #ifndef __2DVectors__
- calcZ = basePart->basePosition[partArrIndex].c;
- #endif
- */
- thisGrafPtr = &(theGrafPtr[j]);
- thisGrafPtr->index = partArrIndex;
- thisCircle = &(thisGrafPtr->circle);
-
- cramersCoordsOfkSanPoint ( &cMat, &basePart->basePosition[partArrIndex], &graphicsCoords);
-
- /*
- #ifndef __2DVectors__
- graphC = ((float) (calcX * (cMat.A.c) +
- calcY * (cMat.B.c) +
- calcZ * (cMat.C.c) ) );
- #endif
- graphA = ((float) (calcX * (cMat.A.a) +
- calcY * (cMat.B.a)
- #ifndef __2DVectors__
- + calcZ * (cMat.C.a)
- #endif
- ) );
-
- graphB = ((float) (calcX * (cMat.A.b) +
- calcY * (cMat.B.b )
- #ifndef __2DVectors__
- + calcZ * (cMat.C.b )
- #endif
- ) );
-
-
- #ifndef __2DVectors__
- depthFactor = viewLen / (viewLen - graphC);
- #endif
- */
-
- thisGrafPtr->grapha = graphicsCoords.a;
- thisGrafPtr->graphb = - graphicsCoords.b;
- #ifndef __2DVectors__
- thisGrafPtr->graphc = graphicsCoords.c;
- #endif
-
- // partSize = theView->particleSizeFactor;
- realSize = ag->setMySize( ag, ag->atArray, theView, basePart, partArrIndex);
-
- halfSize = ((float) realSize) * 0.5;
-
- thisCircle->left = offset.h + thisGrafPtr->grapha - halfSize;
- thisCircle->right = thisCircle->left + realSize;
- thisCircle->top = offset.v + thisGrafPtr->graphb - halfSize;
- thisCircle->bottom = thisCircle->top + realSize;
-
- if ((thisCircle->left > visibleRect.right) ||
- (thisCircle->right < visibleRect.left) ||
- (thisCircle->top > visibleRect.bottom) ||
- (thisCircle->bottom < visibleRect.top) )
- {
- thisGrafPtr->inWindow = false;
- }
- else
- {
- thisGrafPtr->inWindow = true;
- thisGrafPtr->selected = BPNthSelected(basePart, partArrIndex);
- }
- }
- AGWindowReleaseGrafData( ag);
- releaseList( &ag->orderList);
- releaseList( &ag->particleList);
- }
-
-
- void findBonds(AGWindow *ag, particle *basePart, Point offset)
- { // you must set up the ag->atArray list before calling!
- #ifdef __2DVectors__
- #pragma unused (ag)
- #endif
- #pragma unused(offset)
- #pragma unused(basePart)
- #ifndef __2DVectors__
- // long i, j, numNNs;
- long numberOfParts;
- grafData *theGrafPtr;
- // grafData *thisGrafData;
- long * orderListPtr; // need to create a label table to do cross-referencing
- // particle * thisPart;
- viewInfo *theView;
- kSanMatrix cMat;
- float viewLen;
- // float depthFactor;
-
- agCheckOrderList(ag);
- orderListPtr = lockList(&ag->orderList);
- theGrafPtr = AGWindowLockGrafData( ag);
- numberOfParts = AGWindowNumParts(ag);
-
- theView = &ag->windowView;
- viewLen = theView->perspective * theView->magnification;
- getCramerskSanOperatorsD(&theView->viewMatrix, &cMat);
-
- multkSanMatrixD(&cMat, theView->magnification, &cMat);
-
- /*
- for (j= 0; j<numberOfParts ;++j) // j is index in theList
- {
- short howManyForebonds;
- short howManyBackbonds;
- Point *thisFStart;
- Point *thisFEnd;
- Point *thisBStart;
- Point *thisBEnd;
- NNInfo * nni;
- floatVector centerVec, startVec, endVec, partVec, normBondVec;
- floatVector tStartVec, tEndVec;
- float bondLength, shortenBy;
- float thisSize, thatSize;
-
- thisGrafData = &( theGrafPtr[j]);
- if (!(thisGrafData->inWindow))
- {
- thisGrafData->howManyForebonds = 0;
- thisGrafData->howManyBackbonds = 0;
- }
- else // its in the window -- lets make the bonds
- {
- thisPart = &( basePart[thisGrafData->index]); // this part has the particleData
- thisBStart = thisGrafData->backbondStart;
- thisBEnd = thisGrafData->backbondEnd;
- thisFStart = thisGrafData->forebondStart;
- thisFEnd = thisGrafData->forebondEnd;
- partVec.a = thisPart->position.a;
- partVec.b = thisPart->position.b; // double to float
- partVec.c = thisPart->position.c;
- thisSize = ag->setMyActualSize(agObj,ag, ag->atArray, theView, thisPart);
- thisSize *= 0.5;
- cramersCoordsOfkSanPointF(&cMat, &partVec, ¢erVec);
-
- //adjustForDepth(¢erVec, theView, viewLen);
- // view len calculated above
- depthFactor = viewLen / (viewLen - centerVec.c);
- centerVec.a = (centerVec.a * depthFactor) ;
- centerVec.b = (centerVec.b * depthFactor) ;
-
-
- howManyForebonds = 0;
- howManyBackbonds = 0;
-
- // centerVec IS THE SCREEN COORDS OF THE PARTICLE from which the bonds are coming
- nni = lockNNInfo (&basePart[thisGrafData->index].neighbors);
- i = 0;
- numNNs = basePart[thisGrafData->index].neighbors.infoList.howManyItems;
- while ((i<numNNs) && ((howManyForebonds < kMaxBonds) || (howManyBackbonds < kMaxBonds)) )
- {
- // strategy first, check screening != zero
- if (nni[i].screen > 0)
- {
- // then find bond length.
- bondLength = nni[i].sep ;
-
- shortenBy = bondLength * 0.5;
- thatSize = ag->setMyActualSize(agObj,ag, ag->atArray, theView, &basePart[nni[i].nIndex]);
- thatSize *= 0.5;
- // adjust end bond to either half the separation, or by radius of neighbor, whichever longer
- if (thatSize > shortenBy) shortenBy = thatSize;
-
- bondLength = bondLength - shortenBy;
- // check that
- if (bondLength > thisSize)
- {
- // adjust beginning of bond length by radius of part
- normBondVec.a = nni[i].vec.a * nni[i].invSep;
- normBondVec.b = nni[i].vec.b * nni[i].invSep;
- normBondVec.c = nni[i].vec.c * nni[i].invSep;
- // if length is positive, transform beginning and end points into points in graph space
- endVec.a = partVec.a + normBondVec.a * bondLength ;
- endVec.b = partVec.b + normBondVec.b * bondLength ;
- endVec.c = partVec.c + normBondVec.c * bondLength ;
- startVec.a = partVec.a + normBondVec.a * thisSize ;
- startVec.b = partVec.b + normBondVec.b * thisSize ;
- startVec.c = partVec.c + normBondVec.c * thisSize ;
-
- cramersCoordsOfkSanPointF(&cMat, &endVec, &tEndVec);
-
- // adjustForDepth(&tEndVec,theView, viewLen);
- // depth fac calculated above
- tEndVec.a = (tEndVec.a * depthFactor) ;
- tEndVec.b = (tEndVec.b * depthFactor) ;
-
- cramersCoordsOfkSanPointF(&cMat, &startVec, &tStartVec);
-
- // adjustForDepth(&tStartVec, theView, viewLen);
- // depth fac calculated above
- tStartVec.a = (tStartVec.a * depthFactor) ;
- tStartVec.b = (tStartVec.b * depthFactor) ;
-
- // check if its a forebond or back bond
- if (tEndVec.c > tStartVec.c)
- { // its a forebond
- if (howManyForebonds < kMaxBonds)
- {
- thisFStart[howManyForebonds].h = tStartVec.a + offset.h;
- thisFStart[howManyForebonds].v = offset.v - tStartVec.b;
- thisFEnd[howManyForebonds].h = tEndVec.a + offset.h;
- thisFEnd[howManyForebonds].v = offset.v - tEndVec.b;
- ++howManyForebonds;
- } else {}
- }
- else // its a backbond
- {
- if (howManyBackbonds < kMaxBonds)
- {
- thisBStart[howManyBackbonds].h = tStartVec.a + offset.h;
- thisBStart[howManyBackbonds].v = offset.v - tStartVec.b;
- thisBEnd[howManyBackbonds].h = tEndVec.a + offset.h;
- thisBEnd[howManyBackbonds].v = offset.v - tEndVec.b;
- ++howManyBackbonds;
- }
- else {}
- }
- } // end bond had positive length
- } // end screening was not 0
- ++i; // effective loop over i ( number of neighbors )
- } // end while (loop over neighbors
- thisGrafData->howManyForebonds = howManyForebonds;
- thisGrafData->howManyBackbonds = howManyBackbonds;
- releaseNNInfo(&basePart[thisGrafData->index].neighbors);
- } // end of this part is in window
- } // end of loop over number of parts in window
- */
- releaseList(&ag->orderList);
- AGWindowReleaseGrafData( ag);
- #endif
- }
- //void adjustForDepth(floatVecPtr centerVec, viewInfo *theView, float viewLen)
- //{
- // float depthFactor;
-
- // depthFactor = viewLen / (viewLen - centerVec->c);
- // centerVec->a = theView->cellCenter.h + (centerVec->a * depthFactor) ;
- // centerVec->b = theView->cellCenter.v - (centerVec->b * depthFactor) ;
- //}
-
- void screenCoordsOfXYZPoint ( viewInfo *theView, kSanVector * thePos, kSanVector * theCoords);
- void screenCoordsOfXYZPoint ( viewInfo *theView, kSanVector * thePos, kSanVector * theCoords)
- {
- float depthFactor;
- kSanMatrix cMat;
- float mag, viewLen;
-
- #ifdef __2DVectors__
- #pragma unused (depthFactor)
- #endif
-
- mag = theView->magnification;
- viewLen = theView->perspective * mag;
-
- getCramerskSanOperatorsD(&(theView->viewMatrix), &cMat);
- multkSanMatrixD(&cMat, mag, &cMat);
- cramersCoordsOfkSanPoint(&cMat, thePos, theCoords);
-
- #ifndef __2DVectors__
- depthFactor = viewLen / (viewLen - theCoords->c);
-
- theCoords->a = theView->lastOffsetUsed.h + (theCoords->a * depthFactor) ;
- theCoords->b = theView->lastOffsetUsed.v - (theCoords->b * depthFactor) ;
- #else
- theCoords->a = theView->lastOffsetUsed.h + (theCoords->a ) ;
- theCoords->b = theView->lastOffsetUsed.v - (theCoords->b ) ;
- #endif
- }
-
-
- float setNoActualSize(AGWindow *ag, kSanAtomtype **atArray, viewInfo *theView, particle *basePart, long partArrIndex)
- {
- #pragma unused(ag)
- #pragma unused(basePart)
- #pragma unused(partArrIndex)
- #pragma unused(atArray)
- return (5.0 / theView->magnification);
- }
-
- float setMyActualSizeByAtomType(AGWindow *ag, kSanAtomtype **atArray, viewInfo *theView, particle *basePart, long partArrIndex)
- {
- #pragma unused(ag)
- #pragma unused(theView)
- return ( atArray[BPNthType(basePart, partArrIndex)]->specs.drawingRadius );
- }
-
- float setMyActualSizeByWindow(AGWindow *ag, kSanAtomtype **atArray,viewInfo *theView, particle *basePart, long partArrIndex)
- {
- #pragma unused(ag)
- return ( atArray[BPNthType(basePart, partArrIndex)]->specs.drawingRadius * theView->particleSizeFactor );
- }
-
- float setNoSize(AGWindow *ag, kSanAtomtype **atArray,viewInfo *theView, particle *basePart, long partArrIndex)
- {
- #pragma unused(ag)
- #pragma unused(theView)
- #pragma unused(basePart)
- #pragma unused(partArrIndex)
- #pragma unused(atArray)
- return (5.0);
- }
-
- float setMySizeByAtomType(AGWindow *ag, kSanAtomtype **atArray,viewInfo *theView, particle *basePart, long partArrIndex)
- {
- #pragma unused(ag)
- return (atArray[BPNthType(basePart, partArrIndex)]->specs.drawingRadius * theView->magnification);
- }
-
- float setMySizeByWindow(AGWindow *ag, kSanAtomtype **atArray,viewInfo *theView, particle *basePart, long partArrIndex)
- {
- #pragma unused(ag)
- return (atArray[BPNthType(basePart, partArrIndex)]->specs.drawingRadius * theView->magnification * theView->particleSizeFactor);
- }
-
-